package com.controller;

import com.pojo.Prescription;
import com.service.impl.PrescriptionServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (Prescription)表控制层
 *
 * @author makejava
 * @version 1.0
 * @since 2022-04-08 12:33:27
 */
@RestController
@RequestMapping("/prescription")
public class PrescriptionController {
    /**
     * 服务对象
     */
    @Resource
    private PrescriptionServiceImpl prescriptionServiceImpl;


    /**
     * 查询所有数据
     *
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public Map<String, Object> selectAll() {
        return this.prescriptionServiceImpl.selectAll();
    }

    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public Map<String, Object> deleteById(@RequestParam("id") String id) {
        return this.prescriptionServiceImpl.deleteById(id);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public Map<String, Object> selectById(Integer id) {
        return this.prescriptionServiceImpl.selectById(id);
    }

    /**
     * 通过主键更新单条数据
     *
     * @param prescription 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public Map<String, Object> updateById(@RequestBody Prescription prescription) {
        return this.prescriptionServiceImpl.updateById(prescription);
    }

    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param prescription 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public Map<String, Object> insert(@RequestBody Prescription prescription) {
        return this.prescriptionServiceImpl.insert(prescription);
    }

}